package com.yfp.operation.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfp.operation.domain.MachineDO;
import com.yfp.operation.domain.MachineExpireWarnDO;
import com.yfp.operation.domain.dto.WarnParameterDTO;
import com.yfp.operation.domain.vo.MachineErrorVO;
import com.yfp.operation.mapper.MachineExpireWarnMapper;
import com.yfp.operation.mapper.MachineMapper;
import com.yfp.operation.service.MachineExpireWarnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MachineExpireWarnServiceImpl extends ServiceImpl<MachineExpireWarnMapper, MachineExpireWarnDO> implements MachineExpireWarnService {

    @Autowired
    private MachineMapper machineMapper;
    @Autowired
    private MachineExpireWarnMapper machineExpireWarnMapper;


    /**
     * 过期报警
     * @param warnParameterDTO
     * @return
     */
    @Override
    public List<MachineErrorVO> getMachineExpireWarn(WarnParameterDTO warnParameterDTO) {

        // 获取设备信息
        MachineDO machine = machineMapper.getMachine(warnParameterDTO.getMachineId());
        // 过期
        List<MachineErrorVO> expireWarnList = machineExpireWarnMapper.getMachinExpireWarn(warnParameterDTO);
        expireWarnList.forEach(machineError -> {
            machineError.setMachineName(machine.getMachineName());
            machineError.setErrorType(warnParameterDTO.getStatus());
        });

        return expireWarnList;

    }
}
